

package com.yz.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yz.common.entity.*;
import com.yz.dao.DrawingDao;
import com.yz.dao.LogDao;
import com.yz.service.CheckService;
import com.yz.service.DrawingService;
import com.yz.service.LogService;
import com.yz.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service("drawingService")
public class DrawingServiceImpl extends ServiceImpl<DrawingDao,DrawingEntity> implements DrawingService {
    @Autowired
    CheckService checkService;
    @Autowired
    ProjectService projectService;

    @Override
    public long selectId() {
        return this.baseMapper.selectId();
    }
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void postMe(DrawingEntity t) {
        CheckEntity check = new CheckEntity();
        check.setCreateAt(t.getUpdateAt());
        check.setCreateUser(t.getCreateUser());
        check.setName(projectService.selectById(t.getProjectId()).getName());
        if(t.getTypeWhere()==1){
            check.setNameForm(contant.type_name[2]);
        }else{
            check.setNameForm(contant.type_name[3]);
        }
        check.setProjectId(t.getProjectId());
        check.setStatus(1);
        check.setType(2);
        check.setTypeForm(t.getTypeWhere());
        if(t.getId()==0){
            this.baseMapper.insert(t);
            long id = this.baseMapper.selectId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[1]+contant.type_detail_form[12]+id);
            checkService.insert(check);
        }else{
            long id = t.getId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[1]+contant.type_detail_form[12]+id);
            checkService.update(check,new EntityWrapper<CheckEntity>().eq("number",contant.type_all_form[1]+contant.type_detail_form[12]+id));
            this.baseMapper.update(t,new EntityWrapper<DrawingEntity>().eq("id",id));
        }
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void deleteMe(long id) {
        this.baseMapper.deleteById(id);
            checkService.deleteMe(2,id);
    }
    @Override
    public List<Map<String,Object>> selectPictures(Map map) {
        return this.baseMapper.selectPictures(map);
    }

    @Override
    public int selectCountP(Map map) {
        return this.baseMapper.selectCountP(map);
    }
}